import java.util.Stack;

class Solution4 {

    public int evalRPN(String[] tokens) {

        Stack<Integer> stack = new Stack<>();

        for(String x:tokens){

            if(isnumber(x)){

                stack.push(Integer.parseInt(x));

            }

            else{

                int num2 = stack.pop();

                int num1 = stack.pop();

                switch(x){

                    case "+":

                    stack.push(num1+num2);

                    break;

                    case "-":

                    stack.push(num1-num2);

                    break;

                    case "*":

                    stack.push(num1*num2);

                    break;

                    case "/":

                    stack.push(num1/num2);

                    break;

                }

            

        }

    }

    return stack.pop();

    }

    private boolean isnumber(String x){

        if(x.equals("+")||x.equals("-")||x.equals("*")||x.equals("/"))

        {return false;}

         return true;

    }

}